package com.myzombieapocalypse.projectz.web;

import com.myzombieapocalypse.projectz.application.RegisterFacade;
import com.myzombieapocalypse.projectz.web.forms.Registration;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * User: StuartS
 * Date: 26/10/11
 * Time: 19:49
 */
public class RegistrationController extends SimpleFormController{

    private RegisterFacade registerFacade;

    public RegisterFacade getRegisterFacade() {
        return registerFacade;
    }

    public void setRegisterFacade(RegisterFacade registerFacade) {
        this.registerFacade = registerFacade;
    }

    @Override
    protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
        Registration form = (Registration) command;
        registerFacade.createAccount(form);
        return new ModelAndView(getSuccessView());
    }
}
